//
//  FTProfileInforViewController.m
//  FaceTo
//
//  Created by 姚冬元 on 2017/8/11.
//  Copyright © 2017年 chengbangming. All rights reserved.
//

#import "FTProfileInforViewController.h"
#import "FTAvatarHeaderView.h"

@interface FTProfileInforViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UIButton *confirmBtn;

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) FTAvatarHeaderView *headView;

@end

@implementation FTProfileInforViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
}

- (void)initUI
{
    self.view.backgroundColor = WhiteColor;
    
    // nav右边按钮
    _confirmBtn = [[UIButton alloc] init];
    [_confirmBtn setTitle:@"完成" forState:UIControlStateNormal];
    [_confirmBtn setTitleColor:BlackColor forState:UIControlStateNormal];
    _confirmBtn.titleLabel.font = LPFont(15);
    _confirmBtn.frame = CGRectMake(0, 0, 40, 40);
    _confirmBtn.userInteractionEnabled = NO;
    [_confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:_confirmBtn];
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithCustomView:[UIButton buttonWithType:UIButtonTypeCustom]];
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:barBtn, item1, nil];
    
    _headView = [[FTAvatarHeaderView alloc] init];
    _headView.frame = CGRectMake(0, 0, kSCREEN_WIDTH, 150);
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT-64)];
    _tableView.backgroundColor = Color(237, 237, 237);
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    _tableView.tableHeaderView = _headView;
    [self.view addSubview:_tableView];

}

- (void)confirmBtnClick
{
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat yOffset = scrollView.contentOffset.y  ;
    if (yOffset < 0) {
        CGFloat totalOffset = 150 + ABS(yOffset);
        CGFloat f = totalOffset / 150;
        _headView.bgimg.frame = CGRectMake(- (width * f - width) / 2, yOffset, width * f, totalOffset);
    }
}


#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    cell.selectionStyle = NO;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Remove seperator inset
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    // Prevent the cell from inheriting the Table View's margin settings
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
    // Explictly set your cell's layout margins
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

@end
